package org.csu.dormmonitor.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import org.csu.dormmonitor.entity.User;
import org.csu.dormmonitor.mapper.Usermapper;
import org.csu.dormmonitor.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class UserServiceImpl implements UserService {

    @Autowired
    private Usermapper usermapper;

    //获取宿舍成员
    @Override
    public List<User> getUsersList(){
        return  usermapper.selectList(null);
    }

    @Override
    public User getUserById(String id){
        return usermapper.selectById(id);
    }

    @Override
    public void updateUserPasswordById(String id, String password){
        UpdateWrapper<User> updateWrapper=new UpdateWrapper<>();
        updateWrapper.eq("id",id).set("password",password);
        usermapper.update(null,updateWrapper);
    }

    @Override
    public void updateUserPhotoById(String id, String photo){
        UpdateWrapper<User> updateWrapper=new UpdateWrapper<>();
        updateWrapper.eq("id",id).set("photo",photo);
        usermapper.update(null,updateWrapper);
    }

    @Override
    public void updateUserEmailById(String id, String email){
        UpdateWrapper<User> updateWrapper=new UpdateWrapper<>();
        updateWrapper.eq("id",id).set("email",email);
        usermapper.update(null,updateWrapper);
    }


}
